package org.nobject.common.fan.datagen;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.nobject.common.exception.ConvertException;
import org.nobject.common.lang.DateUtils;

/**
 * 日期生成器
 *
 * @author benson
 * @version 1.0
 */
public class DateGen implements RandomGen{
	
	/**
	 * 生成时间
	 * @param beginTime
	 * @param endTime
	 * @param formart
	 * @return
	 * @throws ConvertException 
	 */
	public static String genDate(String beginTime,String endTime,String formart) throws ConvertException{
		long bl=DateUtils.toDate(beginTime).getTime();
		long el=DateUtils.toDate(endTime).getTime();
		long c=el-bl;
		int p=random.nextInt(100);
		double d=p/100d;
		bl+=d*c;
		Calendar nC=Calendar.getInstance();
		nC.setTimeInMillis(bl);
		Date nDate=nC.getTime();
		
		return new SimpleDateFormat(formart).format(nDate);
	}
	
	/** 
	 * genDate
	 * @param beginTime
	 * @param endTime
	 * @return
	 * @throws ConvertException
	 */
	public static String genDate(String beginTime,String endTime) throws ConvertException{
		return genDate(beginTime,endTime,DateUtils.Format.YMDHMS);
	}
	
}
